home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-21 | 2.1 KB | 104 lines | [TEXT/nX^n] |
- /**********************************/
- /* File: Sample.c */
- /* */
- /* A sample XCMD for Hypercard */
- /* 2.0 */
- /* */
- /* Well-behaved XCMDs for HC2.0 */
- /* will respond to the ! and ? */
- /* requests by returning version */
- /* and usage information */
- /* respectively. */
- /* */
- /* ---------------------------- */
- /* ©1990, Donald Koscheka */
- /* All Rights Reserved */
- /**********************************/
-
- /*
- Project:
-
- ANSI-A4 -- standard "C" libraries assembled
- off of register A4
-
- MacTraps
- Sample2.0.c (contents of listing 1)
-
- Set Project Type:
- Type == XCMD | XFCN
- Name == SimpleXCMD
- id == 1000
-
- Usage
-
- SimpleXCMD "?"
- SimpleXCMD "!"
- put the result
-
- OR
-
- Put simpleXCMD( "?" )
- Put simpleXCMD( "!" )
- */
-
- #include <SetUpA4.h>
- #include <string.h>
- #include <HyperXCMD.h>
-
- #ifndef NIL
- #define NIL (void *)0L
- #endif
-
- Handle strToParam( str )
- char *str;
- /***************************
- * Given a pointer to a string,
- * copy that string into a handle
- * and return the handle.
- *
- * The input and output strings
- * are both null-terminated
- *
- ***************************/
- {
- Handle outH = NIL;
- long len = 0;
-
- len = strlen( str );
- if( len )
- if( outH = NewHandle( len ) )
- BlockMove( str, *outH, len + 1 );
-
- return( outH );
- }
-
- pascal void main( paramPtr )
- XCmdPtr paramPtr;
- {
- Handle answer = NIL;
- char *str;
- long len;
-
- paramPtr->returnValue = NIL;
-
- /** The first thing that a well-behaved **/
- /** HC2.0 XCMD should do is check to see **/
- /** whether the first (and only) parameter **/
- /** is the user request for information or **/
- /** or usage information. If so, just pass **/
- /** your answer back to the user, otherwise **/
- /** go ahead and perform your xcmd services **/
-
- if (paramPtr->paramCount == 1){
- if ( **(paramPtr->params[0]) == '!' ){
- paramPtr->returnValue = strToParam("Simple XCMD, version 1.0, ©Donald Koscheka, 1990");
- return;
- }
-
- if ( **(paramPtr->params[0]) == '?' ){
- paramPtr->returnValue = strToParam("Simple takes no parameters and does nothing with them.");
- return;
- }
- }
- }
- Listing 1. SimpleXCMD.c